<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/6/17
 * Time: 16:06
 */

namespace app\api\controller;


use think\Controller;
use think\Request;

class Category extends Controller
{
    protected $model=null;
    public function __construct(Request $request = null)
    {
        //跨域访问
        if (config('app_debug') == true) {
            header("Access-Control-Allow-Origin:*");
            // 响应类型
            header("Access-Control-Allow-Methods:GET,POST");
            // 响应头设置
            header("Access-Control-Allow-Headers:x-requested-with,content-type,x-access-token,x-access-appid");
        }
        $this->model=new \app\api\model\Category();

        parent::__construct($request);
    }

    public function index(Request $request){
        if($request->isGet()){
            $page=$request->param('page');
            $pagenum=$request->param('pagenum');
            $model=$this->model;
            $obj=$model->where('isshow','=',1)->page($page,$pagenum)->select();

            $total=$model->where('isshow','=',1)->count();

            $collect=collection($obj);
            $arr=$collect->toArray();

            $arr['total']=$total;
            $arr['pagenum']=$pagenum;
            $arr['page']=$page;
            return json(['status'=>200,'msg'=>'获取成功','data'=>$arr]);
        }else{
            return json(['status'=>400,'msg'=>'请求失败']);
        }
    }
}